﻿package com.xuanque.mahjongDice.control
{
	import flash.utils.ByteArray;
	import command.Command;
	import command.MajDiceCommand;
	
	import utils.HallConfig;
	import utils.Reflection;
	
	import flash.system.ApplicationDomain;
	
	public class SendPackage
	{
		
		private static var Instance:SendPackage = new SendPackage();
		
		public function SendPackage(){
			if(Instance!=null){
				throw new Error("单件")
			}
		}
		
		/*
		 * 单件类的实例 
		*/
		public static function getInstance():SendPackage {
			
			return Instance;
		}
		
		public function setStaticObjectNull():void{
		    Instance = null;
		}
		
		
		/*
		 * 准备
		*/ 
		public function sendReady():void{
			trace("发送准备包");
			var sendArray:ByteArray = new ByteArray();
			getClass().sendGamePkg(Command.USER_READY_PLAY_GAME,sendArray);
		}
		
		/*
		 * 玩家出	骰
		*/
		public function getOutPai(num:int):void{
			trace("玩家出骰="+num);
			var sendArray:ByteArray = new ByteArray();
			var moneyArray:ByteArray = new ByteArray();
			moneyArray.length = 1;
			moneyArray.writeByte(num);
			sendArray.writeBytes(moneyArray);
			getClass().sendGamePkg(MajDiceCommand.USER_SEND_OUT_DICE,sendArray);
		}
		
		
		/*
		 * 胡牌
		*/
		public function huPai():void{
			
			var sendArray:ByteArray = new ByteArray();
			getClass().sendGamePkg(MajDiceCommand.USER_SEND_COMPLETED_HAND,sendArray);
		}
		
		/*
		 * 摇骰
		*/
		public function shaking():void{
			
			var sendArray:ByteArray = new ByteArray();
			getClass().sendGamePkg(MajDiceCommand.USER_SHAKE_DICE,sendArray);
			trace("摇骰 发包");
		}
		
		/*
		 * 托管
		*/
		public function trusteeship():void{
			
			var sendArray:ByteArray = new ByteArray();
			getClass().sendGamePkg(MajDiceCommand.USER_RES_AGENT,sendArray);
			trace("托管 发包");
		}
		
		/*
		 * 取消托管
		*/
		public function untrusteeship():void{
			
			var sendArray:ByteArray = new ByteArray();
			getClass().sendGamePkg(MajDiceCommand.USER_RES_AGENT_CANCEL,sendArray);
			trace("取消托管 发包");
		}
		
		/*
		 * 离开桌子  0x30004
		*/
		public function sendLeave():void{
			var sendArray:ByteArray = new ByteArray();
			getClass().sendGamePkg(Command.LEAVE_TABLE_RES,sendArray);
		}
		
		/*
		 * 发送聊天信? 0x30007
		*/
		public function sendWords(content:String):void{
			var sendArray:ByteArray = new ByteArray();
			
			var wordArray:ByteArray = new ByteArray();
			wordArray.length = 90;
			wordArray.writeMultiByte(content,"utf-8");
			sendArray.writeBytes(wordArray);

			getClass().sendGamePkg(Command.PLAYER_TABLE_CHAT,sendArray);
		}
		
		private function getClass():Class{
			return Reflection.getClass("controller.MajDiceController",HallConfig.getIntance().getApplication());
			return null;
		}
		
		

	}
}